#include <wx/wxprec.h>
#include <wx/wx.h>
#include <wx/splitter.h>
#include <wx/notebook.h>
#include <wx/listctrl.h>
#include <wx/treectrl.h>
#include <wx/config.h>
#include <wx/utils.h>

#include "PropertyEx.h"

void ModifyValue(wxPGProperty* p, wxVariant value)
{
	wxString strType = value.GetType();
	
	wxPGProperty::ClientDataType pData = p->GetClientData();
	_U8 type = ((PropClientData*)pData)->type;

	switch(type)
	{
	case DDLReflect::TYPE_U8:		
		{
			CPropertyEx<_U8, wxIntProperty>* pp = (CPropertyEx<_U8, wxIntProperty>*)p;
			pp->ModifyValue((_U8)value.GetInteger());
		}
		break;
	case DDLReflect::TYPE_U16:	
		{
			CPropertyEx<_U16, wxIntProperty>* pp = (CPropertyEx<_U16, wxIntProperty>*)p;
			pp->ModifyValue((_U16)value.GetInteger());
		}
		break;
	case DDLReflect::TYPE_U32:	
		{
			CPropertyEx<_U32, wxIntProperty>* pp = (CPropertyEx<_U32, wxIntProperty>*)p;
			pp->ModifyValue((_U32)value.GetInteger());
		}
		break;
	case DDLReflect::TYPE_U64:	
		{
			CPropertyEx<_U64, wxIntProperty>* pp = (CPropertyEx<_U64, wxIntProperty>*)p;
			pp->ModifyValue((_U64)value.GetLong());
		}
		break;
	case DDLReflect::TYPE_S8:
	case DDLReflect::TYPE_S16:
	case DDLReflect::TYPE_S32:	
	case DDLReflect::TYPE_S64:
		{
			wxMessageBox(_("No this data type"));
		}
		break;
	case DDLReflect::TYPE_F32:	
		{
			CPropertyEx<_F32, wxFloatProperty>* pp = (CPropertyEx<_F32, wxFloatProperty>*)p;
			pp->ModifyValue((_F32)value.GetDouble());
		}
		break;
	case DDLReflect::TYPE_F64:
		{
			CPropertyEx<_F64, wxFloatProperty>* pp = (CPropertyEx<_F64, wxFloatProperty>*)p;
			pp->ModifyValue((_F64)value.GetDouble());
		}
		break;
	case DDLReflect::TYPE_STRING:
		{
			CPropertyEx<wxString, wxStringProperty>* pp = (CPropertyEx<wxString, wxStringProperty>*)p;
			pp->ModifyValue(((wxString)value.GetString()).c_str());
		}
		break;
	case DDLReflect::TYPE_UUID:
		{
			CPropertyEx<wxString, wxStringProperty>* pp = (CPropertyEx<wxString, wxStringProperty>*)p;
			pp->ModifyValue(((wxString)value.GetString()).c_str());
		}
		break;
	case DDLReflect::TYPE_STRUCT:
		{
			wxMessageBox(_("Do not modify this data"));
		}
		break;
	case DDLReflect::TYPE_MASK:
		{
			wxMessageBox(_("Do not modify this data"));
		}
		break;
	case DDLReflect::TYPE_ARRAY:
		{
			_U32 size = (_U32)value.GetInteger();
			if(size > p->GetChildCount())
			{
				wxMessageBox(_("Do not beyond size limit"));
				size = p->GetChildCount();
			}

			for(_U32 i = 0; i < p->GetChildCount(); ++i)
			{
				wxPGProperty* pp = p->Item(i);
				if(i<size)
				{
					pp->Hide(false);
				}
				else
				{
					pp->Hide(true);
				}
			}

			CPropertyEx<wxString, wxStringProperty>* pp = (CPropertyEx<wxString, wxStringProperty>*)p;
			char szValue[32];
			sprintf(szValue, "%u", size);
			pp->ModifyValue(szValue);
			p->SetValueFromString(szValue);	
		}
		break;
	case DDLReflect::TYPE_UUID_REF:
		{
			assert(0);	
		}
		break;
	default:
		{
			assert(0);
		}
		break;
	}
}
